import Router from 'vue-router';

Vue.use(Router);
let routers = []
const routerContext = require.context('./views', true, /router\.js/)
routerContext.keys().forEach(route => {
    // 如果是根目录的 index.js、 不做任何处理
    if (route.startsWith('./index')) {
        return
    }
    const routerModule = routerContext(route)
    // 兼容 import export 和 require module.export 两种规范 Es modules commonjs
    routers = [...routers, ...(routerModule.default || routerModule)]
})
export default new Router({
    routes: [
        {
            path: '/',
            redirect: '/dashboard'
        },
        {
            path: '/',
            component: resolve => require(['./components/common/Home.vue'], resolve),
            meta: {title: '主页'},
            children: routers
        },
        {
            path: '/login',
            component: resolve => require(['./views/Login.vue'], resolve)
        },

        {
            path: '/projectList',
            component: resolve => require(['./views/ProjectList.vue'], resolve)
        },
        {
            path: '*',
            redirect: '/404'
        },

    ]
})
